// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
//安装axios
import axios from 'axios'
import VueAxios from 'vue-axios'
//引入基本全局样式
import '../static/css/base.css'
import 'element-ui/lib/theme-chalk/index.css'
import '../static/css/iconfont.css'
import '../static/js/iconfont'

//富文本编辑器
import '../static/js/wangEditor.min.js'
//引入store
import store from './vuex/store'
//滚动条
import { HappyScroll } from 'vue-happy-scroll'
//自定义组件名
Vue.component('happy-scroll', HappyScroll)
// 引入滑动栏css
import 'vue-happy-scroll/docs/happy-scroll.css'
Vue.config.productionTip = false
//引入jquery
import "../plugins/zTree/js/jquery-1.4.4.min";
//引入Element-ui
Vue.use(ElementUI);
/* eslint-disable no-new */
//axios的使用
Vue.use(VueAxios, axios)
Vue.prototype.$axios = axios;
//引入右键菜单
import EVueContextmenu from 'e-vue-contextmenu'
Vue.use(EVueContextmenu);
//引入markdown编辑器
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)
//引入marked框架
import marked from 'marked'
//让axios携带cookie
axios.defaults.withCredentials=true;
axios.defaults.baseURL='http://api.kernelylz.cn:8008/api/v1'
Vue.config.productionTip = false
//路由拦截器
router.beforeEach(({meta,path},from,next)=>{
  let {auth=true}=meta;//该路由是否需要登录
  let $user=JSON.parse(sessionStorage.getItem('$user'))||{};
  let isLogin=Boolean($user.auth);
  if(!auth&&!isLogin&&path!='/login'){
    return next({path:'/login'})
  }else {
    next()
  }
});

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
})
